package test1;

import java.util.*;

class Ticket{
    int num=0;
    int all;
    boolean flag = false; //true 有票 false 无票
    public Ticket(int num) {
        this.all = num;
    }

     synchronized void dispot(){
        if(flag==false){
            System.out.println("存入第【" + (++num) + "】号票");
            flag = true;
            notify();
        } else {
            try {
                wait();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }

    synchronized void sell() {

        if (flag == true) {
            System.out.println("售出第【" +  (num) + "】号票");
            flag = false;
            notify();
        } else {
            try {
                wait();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }

}

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n =sc.nextInt();
        Ticket ticket = new Ticket(n);

        Thread t1  = new Thread(new Runnable() {
            @Override
            public void run() {
                for(int i=0;i<n;i++){
                    ticket.dispot();
                }
            }
        });
        t1.start();

        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                for(int i=0;i<n;i++){
                    ticket.sell();
                }
            }
        });
        t2.start();
    }
}
